<template>
    <div class="change-car">
        <div class="change-car-mes">
            <span>过车单用于办理未入仓的货物出仓，过车完成后自动生成出仓单</span>
        </div>
         <van-pull-refresh v-model="changeCarData.refreshing" @refresh="refresh">
             <van-list
                v-model:loading="changeCarData.loading"
                :finished="changeCarData.finished"
                finished-text="没有更多了"
                @load="getList"
                class="change-car-list"
            >
                <div class="section font-size-26" v-for="item in changeCarData.list" :key="item.changeId">
                    <div class="section-permi" v-hasPermi="['zhcloud:changeCar:info']" @click="goDetail(item)"></div>
                    <div>
                        <div :class="[item.orderStatus == '0'?'border-left-CE0C0C':'border-left-2CB526','title display-flex justify-between align-center']">
                            <div>
                                <span class="font-666666">过车单号：</span>
                                <span>{{ item.orderNo }}</span>
                            </div>
                            <span class="font-2CB526" v-if="item.orderStatus == '1'">已审核</span>
                            <span class="font-CE0C0C" v-else>未审核</span>
                        </div>
                        <div class="content display-flex justify-between">  
                            <div class="flex-item">
                                <div class="item display-flex">
                                    <span class="label">件数：</span>
                                    <span>{{ item.spjs }}件</span>
                                </div>
                                <div class="item display-flex">
                                    <span class="label">重量：</span>
                                    <span>{{ item.spsl }}吨</span>
                                </div>
                                
                                <div class="item display-flex">
                                    <span class="label">车牌号：</span>
                                    <span>{{ item.cardNo }}</span>
                                </div>
                                <div class="item display-flex">
                                    <span class="label">仓库：</span>
                                    <span>{{ item.spckmc }}</span>
                                </div>
                                <div class="item display-flex">
                                    <span class="label">过车日期：</span>
                                    <span>{{ item.changeDate }}</span>
                                </div>
                                
                            </div>
                            <div class="flex-item">
                                <div class="item display-flex">
                                    <span class="label">创建者：</span>
                                    <span>{{ item.createBy }}</span>
                                </div>
                                <div class="item display-flex">
                                    <span class="label">创建时间：</span>
                                    <span class="flex-item">{{ item.createTime }}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </van-list>
         </van-pull-refresh>
        <div class="change-car-btn">
            <van-button color="#255FB6" block class="btn" @click="handleAppoint" v-hasPermi="['zhcloud:changeCar:add']">过车办单</van-button>
        </div>
    </div>
</template>
<script setup lang="ts">
    import { onMounted, reactive, inject, computed, onUnmounted  } from 'vue'
    import { getChangeCarList } from '@/api/changeCar'
    import { getWarehouse23 } from '@/api/warehouse'
    import { useRouter, useRoute } from 'vue-router'
    import { msgError } from '@/utils/message'
    import { getLocalStorage,setLocalStorage } from '@/utils/localStorage'
    import PeriodPicker from '@/components/periodPicker.vue'
    import { useHeaderBarStore } from '@/store/headerBar'

    const router = useRouter()
    const route = useRoute()
    const headerBarStore = useHeaderBarStore()
    const userInfo: any = getLocalStorage('userInfo')
    const warehouse23Data: any = reactive({
        query:{},
        list:[]
    })
    const changeCarData: any = reactive({
        loading:false,
        finished:false,
        refreshing: false,
        query: {
            cardNo: "",
			orderNo: "",
			startChangeDate: "",
			endChangeDate: "",
			khmcId: userInfo.shopId,
			spcwid:"",
			orderStatus: "",
			spbhGh: "",
			spckid: "",
			sptm: "",
        },
        list: [],
        total: 0,
        params:{
            pageNum: 1,
            pageSize: 10
        }
       
    })
    
    onMounted(() => {
        getList()
    })

    function getList() {
        changeCarData.loading = true
        getChangeCarList(changeCarData.query, changeCarData.params).then((res: any) => {
            changeCarData.loading = false
            if(res.code == 200) {
                changeCarData.total = res.total
                if(changeCarData.total <= changeCarData.params.pageSize) {
                    changeCarData.list = res.rows
                } else {
                    changeCarData.params.pageNum++
                    changeCarData.list = changeCarData.list.concat(...res.rows)
                }
                if(changeCarData.list.length >= changeCarData.total) {
                    changeCarData.finished = true
                }
            } else {
                changeCarData.finished = true
            }
           
        })
    }

    function refresh() {
        if(changeCarData.refreshing) {
            changeCarData.params.pageNum = 1
            changeCarData.list = []
            changeCarData.total = 0
            changeCarData.refreshing = false
        }
        changeCarData.finished = false
        getList()
    }

    function handleAppoint() {
        setLocalStorage('changeCar',null)
        router.push({path:'/changeCar/appoint'})
    }

    function goDetail(data: any) {
        router.push({path:'/changeCar/detailList', query:{changeId:data.changeId}})
    }
</script>
<style lang="scss" scoped>
    .change-car {
        &-mes {
            width:100%;
            background:#facd91;
            text-align:center;
            padding:15px 0px;
            span {
                font-size: 24px;
            }
        }
        &-sum {
            padding:36px;
            font-size:26px;
        }
        &-list {
            padding:36px 36px 96px;
            .section {
                border-radius: 10px;
                background-color:#fff;
                padding:26px 26px 26px 0;
                margin-bottom:20px;
                position:relative;
                &-permi {
                    width:100%;
                    height:100%;
                    position:absolute;
                    top:0px;
                    left:0px;
                    right:0px;
                    bottom:0px;
                }
                .border-left-CE0C0C {
                    border-left:8px solid #CE0C0C;
                }
                .border-left-2CB526 {
                    border-left:8px solid #2CB526;
                }
                .title {
                    padding-left:18px;
                    margin-bottom: 26px;
                    
                }
                .content {
                    border-top:1px solid #EEEEEE;
                    margin-left:26px;
                    padding:26px 0 0;
                    .item {
                        padding-bottom:20px;
                        .label {
                            color:#999;
                            width:140px;
                            display:inline-block;
                        }
                    }
                }
                
            }
        }
        &-btn {
            position:fixed;
            bottom:0;
            left:0;
            right:0;
            padding:20px 36px;
            .btn {
                border-radius: 10px;
            }
        }
    }
</style>